clear;clc;
%% Device connection
tek=EquipmentControl.AWG.TektronixAFG3252('visa-usb',  'USB0::0x0699::0x034E::B020603::0::INSTR');
ni = EquipmentControl.NIDAQ.NIUSB6366('dev1');


%% TEK sin wave with noise
tek.setWave(1, 'shape', 'PRN', 'amplitude', 0.1);
tek.setBurstState(1, 'OFF');
tek.fire(1);

%% NI

disp('start averaging');
ni.addInputChannel(0).setChannelNameList({'ch0'});
ni.setSampling(3600, 800, 1);
ni.startScope().addSpectrum(100);
ni.wait();
disp('finish averaging');


%% 
ni.stopScope();

%% Plot
figure;
subplot(1, 2, 1);
semilogy(flist, dataAll)
xlabel('Frequency [Hz]');
ylabel('Averaged Noise Amplitude [Vpp]');

subplot(1, 2, 2);
bgNoise = mean(dataAll(180:280, :), 1);
loglog(ampList, bgNoise, 'bo-');
xlabel('Generated Noise Amplitude [V]');
ylabel('Measured Noise Amplitude [Vpp]');

%% Disconnect and Clean Up
fclose(obj1);